﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Iprojects.Data;
using System.Linq;
namespace Iprojects.Forms
{
    public partial class FormLogin : Form
    {
        #region CTOR
        public FormLogin()
        {
            InitializeComponent();
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {

            using (ZakahEntities db = new ZakahEntities())
            {
                try
                {
                    User _user = db.Users.FirstOrDefault(x => (x.username == txtusername.Text) && (x.password == txtPassword.Text));
                    if (null != _user)
                    {
                        if (_user.id > 0)
                        {
                            // log in 
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("حاول مرة اخرى");
                    }
                   

                }
                catch
                {
                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }



            }
        }

        void FormLogin_Disposed(object sender, EventArgs e)
        {
             this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

      



    }
}